﻿using System;
using System.Collections.Generic;

namespace RefLib.Data
{
    public class Pager<T>
    {
        public List<T> Page(int page, int pageSize, IEnumerable<T> collection)
        {
            var allItems = new List<T>(collection);
            var pagedItems = new List<T>();
            
            int startIndex = (page - 1) * pageSize;
            if (startIndex > allItems.Count)
                return pagedItems;

            int stopIndex = Math.Min(startIndex + pageSize, allItems.Count);
            for (int i = startIndex; i < stopIndex; ++i)
            {
                pagedItems.Add(allItems[i]);
            }
            return pagedItems;
        }
    }
}
